<template>
  <view class="p-h24 p-t40" style="padding-bottom: 208rpx">
    <ResumePreview v-if="resume" :resume="resume" />
    <view class="p-h24 flex-sb bg-1 foot">
      <view class="flex-1 flex">
        <view class="flex-d-c action" @click="handleCollect">
          <image v-if="resume.sc" class="icon" src="@/static/images/public/uncollect.png" />
          <image v-else class="icon" src="@/static/images/public/collect.png" />
          <text class="text-400-128">{{ resume.sc ? '已收藏' : '收藏' }}</text>
        </view>
        <view class="flex-d-c action" @click="handleRejectResume">
          <image v-if="resume.td_status === 2" class="icon" src="@/static/images/public/uncollect.png" />
          <image v-else class="icon" src="@/static/images/public/collect.png" />
          <text class="text-400-128">不合适</text>
        </view>
      </view>
      <RcButton :width="192" text="通知面试" :top="0" :size="28" @click="handleOpenNotify" />
    </view>
    <up-popup :show="interviewNoticeVisible" mode="bottom" closeOnClickOverlay @close="interviewNoticeVisible = false">
      <InterviewNotice :id="td_id" @close="handleClose" />
    </up-popup>
  </view>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import RcButton from '@/components/button.vue'
import InterviewNotice from './components/interview-notice'
import type { TResume } from '@/types/api.d'
import ResumePreview from '@/components/resume-preview'
const user_id = ref('')
const td_id = ref('')
const resume = ref<TResume>({})
const interviewNoticeVisible = ref<boolean>(false)
//打开弹窗
function handleOpenNotify() {
  if (!td_id.value) {
    return uni.showToast({ title: "请在“收到的简历投递”里进行通知面试", icon: "none" })
  }
  if (resume.value.td_status == 1) {
    return uni.showToast({ title: "已邀请面试", icon: "none" })
  }
  if (resume.value.td_status == 1) {
    return uni.showToast({ title: "不合适", icon: "none" })
  }
  if (resume.value.td_status == 0) {
    interviewNoticeVisible.value = true
  }

}
//关闭弹窗
function handleClose() {
  interviewNoticeVisible.value = false
  getInfo()
}
const handleCollect = () => {
  uni.showLoading({ mask: true })
  if (resume.value.sc) {
    uni.$u.post('/resume/delsc', { user_id: user_id.value }).then((res) => {
      uni.$u.toast(res.msg)
      if (res.code === 1) {
        // 更新简历信息
        getInfo()
      }
    }).finally(() => {
      uni.hideLoading()
    })
  } else {
    uni.$u.post('/resume/addsc', { user_id: user_id.value }).then((res) => {
      uni.$u.toast(res.msg)
      if (res.code === 1) {
        // 更新简历信息
        getInfo()
      }
    }).finally(() => {
      uni.hideLoading()
    })
  }

}
//标记不合适
const handleRejectResume = () => {
  uni.showModal({
    title: '提示',
    content: '你确定要标记不合适吗',
    success: async function (res) {
      if (res.confirm) {
        uni.showLoading({ mask: true })
        uni.$u.post('/resume/nojl', { user_id: user_id.value }).then((res) => {
          if (res.code === 1) {
            uni.$u.toast('标记成功')
            // 更新简历信息
            getInfo()
          }
        }).finally(() => {
          uni.hideLoading()
        })
      } else if (res.cancel) {
        console.log('取消');
      }
    }
  });

}
//获取个人信息
const getInfo = async () => {
  const res = await uni.$u.get('/resume/resume_info', { id: user_id.value })
  resume.value = res.data
}

onLoad(e => {
  user_id.value = e.user_id
  td_id.value = e.id
  getInfo()
})
</script>

<style lang="scss">
page {
  background-color: $page-color-4;
}
</style>

<style lang="scss" scoped>
.foot {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 168rpx;

  .action {
    width: 100rpx;
  }

  .icon {
    width: 48rpx;
    height: 48rpx;
  }
}
</style>
